package org.secmem.takenoteclient;

import java.util.Date;
import java.util.HashMap;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Color;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.telephony.SmsMessage;
import android.util.Log;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.samsung.samm.common.SObjectStroke;
import com.samsung.sdraw.PenSettingInfo;
import com.samsung.spen.settings.SettingStrokeInfo;
import com.samsung.spensdk.SCanvasConstants;
import com.samsung.spensdk.SCanvasView;
import com.samsung.spensdk.applistener.HistoryUpdateListener;
import com.samsung.spensdk.applistener.SCanvasInitializeListener;
import com.samsung.spensdk.applistener.SPenTouchListener;
import com.samsung.spensdk.applistener.SettingStrokeChangeListener;

public class MainActivity extends FragmentActivity {

	// debug 관련
	public static final String TAG = "TakeNote";
	// 전체
	private Context mContext = null;
	LinearLayout mLinear;

	static int[] images = { R.drawable.a1, R.drawable.a2, R.drawable.a3,
			R.drawable.a4 };

	// 페이저 관련
	TakeNotePagerAdapter mAdapter;
	ViewPager mPager;
	int mOldPager = 0;
	// 제스처
	GestureDetector mGesture;
	// S-Pen 관련 parameter
	// ==============================
	// Application Identifier Setting
	// "SDK Sample Application 1.0"
	// ==============================
	private final String APPLICATION_ID_NAME = "SDK Sample Application";
	private final int APPLICATION_ID_VERSION_MAJOR = 1;
	private final int APPLICATION_ID_VERSION_MINOR = 0;
	private final String APPLICATION_ID_VERSION_PATCHNAME = "Debug";
	int mCanvasIndex = 0;
	private SCanvasView mSCanvas;
	final PenSettingInfo PS_INFO = new PenSettingInfo();
	private float myStrokeWidth = 1.0f;
	RelativeLayout settingViewContainer;

	Button mPenBtn;
	Button mEraserBtn;
	Button mRedoBtn;
	Button mUndoBtn;

	/*
	 * 좌표관련
	 */
	float mX;
	float mY;
	public static int SCANVAS_WIDTH;
	public static int SCANVAS_HEIGHT;
	public static int IMAGEVIEW_WIDTH;
	public static int IMAGEVIEW_HEIGHT;

	// Update tool button
	private void updateModeState() {
		int nCurMode = mSCanvas.getCanvasMode();
		// mPenBtn.setSelected(nCurMode==SCanvasConstants.SCANVAS_MODE_INPUT_PEN);
		// mEraserBtn.setSelected(nCurMode==SCanvasConstants.SCANVAS_MODE_INPUT_ERASER);
	}

	SCanvasInitializeListener mSCanvasInitializeListener = new SCanvasInitializeListener() {

		public void onInitialized() {

			// --------------------------------------------
			// Start SCanvasView/CanvasView Task Here
			// --------------------------------------------
			// Application Identifier Setting
			if (!mSCanvas.setAppID(APPLICATION_ID_NAME,
					APPLICATION_ID_VERSION_MAJOR, APPLICATION_ID_VERSION_MINOR,
					APPLICATION_ID_VERSION_PATCHNAME))
				Toast.makeText(mContext, "Fail to set App ID.",
						Toast.LENGTH_LONG).show();

			// Set Title
			if (!mSCanvas.setTitle("SPen-SDK Test"))
				Toast.makeText(mContext, "Fail to set Title.",
						Toast.LENGTH_LONG).show();

			// Update button state
			updateModeState();

			// // Set Background Image
			// if (!mSCanvas.setBGImage(mBGBitmap)) {
			// Toast.makeText(mContext,
			// "Fail to set Background Image Bitmap.",
			// Toast.LENGTH_LONG).show();
			// }
		};
	};

	/*
	 * com.samsung.spensdk.applistener Interface HistoryUpdateListener
	 * 
	 * 
	 * public interface HistoryUpdateListener 편집 히스토리 관련 S-Canvas기반 리스너 인터페이스
	 */
	private HistoryUpdateListener mHistoryUpdateListener = new HistoryUpdateListener() {

		public void onHistoryChanged(boolean arg0, boolean arg1) {
			// TODO Auto-generated method stub

		}
	};
	/*
	 * public interface SettingStrokeChangeListener 펜 및 지우개 설정과 관련된 값들의 변경이 발생했을
	 * 때 호출되는 S-Canvas기반 리스너 인터페이스
	 * 
	 * void onClearAll(boolean bClearAllCompleted) 지우개 설정창의 "모두삭제" 버튼이 클릭되었을
	 * 때호출되는 콜백 함수 param bClearAllCompleted "모두 삭제" 기능이 수행 완료되었는지 여부 (수행전 false,
	 * 수행후 true) void onEraserWidthChanged(int eraserWidth) 지우개 굵기가 변경되었을 때 호출되는
	 * 콜백 함수 void onStrokeAlphaChanged(int strokeAlpha) 획 색깔의 투명도(alpha) 변경되었을 때
	 * 호출되는 콜백 함수 void onStrokeColorChanged(int strokeColor) 획 색깔이 변경되었을 때
	 * 호출되는콜백 함수 void onStrokeStyleChanged(int strokeStyle) 획 스타일(종류)이 변경되었을 때
	 * 호출되는콜백 함수 void onStrokeWidthChanged(int strokeWidth) 획 굵기가 변경되었을 때 호출되는
	 * 콜백 함수
	 */
	SettingStrokeChangeListener mSettingStrokeChangeListener = new SettingStrokeChangeListener() {

		public void onStrokeWidthChanged(int arg0) {
			// TODO Auto-generated method stub

		}

		public void onStrokeStyleChanged(int strokeStyle) {
			if (strokeStyle == SObjectStroke.SAMM_STROKE_STYLE_PENCIL)

				Log.i(TAG, "Stroke Style = Pen");
			// Toast.makeText(this,"dd",Toast.LENGTH_LONG).show();
			else if (strokeStyle == SObjectStroke.SAMM_STROKE_STYLE_BRUSH)
				Log.i(TAG, "Stroke Style = Brush");
			else if (strokeStyle == SObjectStroke.SAMM_STROKE_STYLE_CRAYON)
				Log.i(TAG, "Stroke Style = Pencil Crayon");
			else if (strokeStyle == SObjectStroke.SAMM_STROKE_STYLE_MARKER)
				Log.i(TAG, "Stroke Style = Marker");

		}

		public void onStrokeColorChanged(int arg0) {
			// TODO Auto-generated method stub

		}

		public void onStrokeAlphaChanged(int arg0) {
			// TODO Auto-generated method stub

		}

		public void onEraserWidthChanged(int arg0) {
			// TODO Auto-generated method stub

		}

		public void onClearAll(boolean arg0) {
			// TODO Auto-generated method stub

		}
	};
	private OnClickListener undoBtnClickListener = new OnClickListener() {
		public void onClick(View v) {
			if (v.equals(mUndoBtn)) {
				// mSCanvas.undo();

				final String items[] = { "Black", "Red", "Blue" };
				final SettingStrokeInfo strokeInfo;
				strokeInfo = mSCanvas.getSettingStrokeInfo();

				AlertDialog.Builder builder = new AlertDialog.Builder(
						MainActivity.this);
				builder.setTitle("Color Selected");
				builder.setSingleChoiceItems(items, -1,
						new DialogInterface.OnClickListener() {

							public void onClick(DialogInterface dialog,
									int which) {
								// TODO Auto-generated method stub
								switch (which) {
								case 0:
									// mSCanvas.setCanvasMode(SCanvasConstants.SCANVAS_MODE_INPUT_PEN);
									PS_INFO.setPenType(PS_INFO.getPenType());
									PS_INFO.setPenColor(Color.BLACK);
									// PP.setPenAlpha(5);
									mSCanvas.setPenSettingInfo(PS_INFO);

									break;
								case 1:

									// PP.setPenAlpha(PP.getPenAlpha());
									PS_INFO.setPenType(PS_INFO.getPenType());
									PS_INFO.setPenColor(Color.RED);
									// PP.setPenAlpha(5);
									mSCanvas.setPenSettingInfo(PS_INFO);
									// mSCanvas.setCanvasMode(SCanvasConstants.SCANVAS_MODE_INPUT_PEN);
									// strokeInfo.setStrokeColor(Color.RED);
									// mSCanvas.setSettingStrokeInfo
									// (strokeInfo);
									break;
								case 2:
									// mSCanvas.setCanvasMode(SCanvasConstants.SCANVAS_MODE_INPUT_PEN);
									PS_INFO.setPenType(PS_INFO.getPenType());
									PS_INFO.setPenColor(Color.BLUE);
									// PP.setPenAlpha(5);
									mSCanvas.setPenSettingInfo(PS_INFO);
									break;

								}
							}
						});
				builder.setPositiveButton("확인",
						new DialogInterface.OnClickListener() {

							public void onClick(DialogInterface dialog,
									int which) {
								// TODO Auto-generated method stub

							}
						});
				builder.show();

				// strokeInfo.setStrokeWidth(myStrokeWidth);

				// float x = mSCanvas.getX();
				// float y = mSCanvas.getY();
				// mSCanvas.panTo(x, y);

			}
			// mUndoBtn.setEnabled(mSCanvas.isUndoable());
			// mRedoBtn.setEnabled(mSCanvas.isRedoable());
		}
	};
	private OnClickListener redoBtnClickListener = new OnClickListener() {
		public void onClick(View v) {

			if (v.equals(mRedoBtn)) {

				final String items[] = { "Pen", "Marker" };
				final SettingStrokeInfo strokeInfo;
				final float Markerstyle = 5.0f;
				strokeInfo = mSCanvas.getSettingStrokeInfo();
				// final PenSettingInfo PP = new PenSettingInfo();

				AlertDialog.Builder builder = new AlertDialog.Builder(
						MainActivity.this);
				builder.setTitle("Style Selected");
				builder.setSingleChoiceItems(items, -1,
						new DialogInterface.OnClickListener() {

							public void onClick(DialogInterface dialog,
									int which) {
								// TODO Auto-generated method stub
								switch (which) {
								case 0:
									// mSCanvas.setCanvasMode(SCanvasConstants.SCANVAS_MODE_INPUT_PEN);
									PS_INFO.setPenType(0);
									PS_INFO.setPenColor(PS_INFO
											.getPenColor(PenSettingInfo.PEN_TYPE_MARKER));
									PS_INFO.setPenWidth(1);
									// strokeInfo.setStrokeStyle(PenSettingInfo.PEN_TYPE_MARKER);

									mSCanvas.setPenSettingInfo(PS_INFO);
									break;
								case 1:
									// mSCanvas.setCanvasMode(SCanvasConstants.SCANVAS_MODE_INPUT_PEN);

									PS_INFO.setPenType(3);
									PS_INFO.setPenColor(PS_INFO
											.getPenColor(PenSettingInfo.PEN_TYPE_SOLID));
									// strokeInfo.setStrokeStyle(PenSettingInfo.PEN_TYPE_MARKER);

									mSCanvas.setPenSettingInfo(PS_INFO);
									break;

								}
							}
						});
				builder.setPositiveButton("확인",
						new DialogInterface.OnClickListener() {

							public void onClick(DialogInterface dialog,
									int which) {
								// TODO Auto-generated method stub

							}
						});
				builder.show();

				// mSCanvas.redo();
			}

			// mUndoBtn.setEnabled(mSCanvas.isUndoable());
			// mRedoBtn.setEnabled(mSCanvas.isRedoable());
		}
	};
	OnClickListener mBtnClickListener = new OnClickListener() {
		@Override
		public void onClick(View v) {
			int nBtnID = v.getId();
			// If the mode is not changed, open the setting view. If the mode is
			// same, close the setting view.
			if (nBtnID == mPenBtn.getId()) {
				if (mSCanvas.getCanvasMode() == SCanvasConstants.SCANVAS_MODE_INPUT_PEN) {
					mSCanvas.setSettingViewSizeOption(
							SCanvasConstants.SCANVAS_SETTINGVIEW_PEN,
							SCanvasConstants.SCANVAS_SETTINGVIEW_SIZE_MINI);
					mSCanvas.toggleShowSettingView(SCanvasConstants.SCANVAS_SETTINGVIEW_PEN);
				} else {
					mSCanvas.setCanvasMode(SCanvasConstants.SCANVAS_MODE_INPUT_PEN);
					mSCanvas.showSettingView(
							SCanvasConstants.SCANVAS_SETTINGVIEW_PEN, false);
					updateModeState();
				}
			} else if (nBtnID == mEraserBtn.getId()) {
				if (mSCanvas.getCanvasMode() == SCanvasConstants.SCANVAS_MODE_INPUT_ERASER) {
					mSCanvas.setSettingViewSizeOption(
							SCanvasConstants.SCANVAS_SETTINGVIEW_ERASER,
							SCanvasConstants.SCANVAS_SETTINGVIEW_SIZE_NORMAL);
					mSCanvas.toggleShowSettingView(SCanvasConstants.SCANVAS_SETTINGVIEW_ERASER);
				} else {
					mSCanvas.setCanvasMode(SCanvasConstants.SCANVAS_MODE_INPUT_ERASER);
					mSCanvas.showSettingView(
							SCanvasConstants.SCANVAS_SETTINGVIEW_ERASER, false);
					updateModeState();
				}
			}
		}
	};

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		mLinear = (LinearLayout) findViewById(R.id.linear_layout);
		mContext = this;

		mPenBtn = (Button) findViewById(R.id.settingBtn);
		mPenBtn.setOnClickListener(mBtnClickListener);
		mEraserBtn = (Button) findViewById(R.id.eraseBtn);
		mEraserBtn.setOnClickListener(mBtnClickListener);
		mRedoBtn = (Button) findViewById(R.id.redoBtn);
		mRedoBtn.setOnClickListener(redoBtnClickListener);
		mUndoBtn = (Button) findViewById(R.id.undoBtn);
		mUndoBtn.setOnClickListener(undoBtnClickListener);

		mGesture = new GestureDetector(getApplicationContext(),
				new GestureDetector.SimpleOnGestureListener() {
					@Override
					public boolean onSingleTapConfirmed(MotionEvent e) {
						// 한손가락 눌럿다 뗏을 경우
						settingViewContainer.setVisibility(View.INVISIBLE);

						return super.onSingleTapConfirmed(e);
					}
				});

		mAdapter = new TakeNotePagerAdapter(getSupportFragmentManager());

		mPager = (ViewPager) findViewById(R.id.pager);
		mPager.setAdapter(mAdapter);
		mPager.setVisibility(View.VISIBLE);
		mSCanvas = (SCanvasView) findViewById(R.id.canvas_view);
		mSCanvas.setVisibility(View.VISIBLE);
		mSCanvas.setSPenTouchListener(new SPenTouchListener() {

			public boolean onTouchPenEraser(View arg0, MotionEvent arg1) {
				// TODO Auto-generated method stub
				return false;
			}

			public boolean onTouchPen(View arg0, MotionEvent arg1) {
				// TODO Auto-generated method stub
				return false;
			}

			public boolean onTouchFinger(View arg0, MotionEvent arg1) {
				// TODO Auto-generated method stub
				return false;
			}

			public void onTouchButtonUp(View arg0, MotionEvent arg1) {
				// TODO Auto-generated method stub

			}

			public void onTouchButtonDown(View arg0, MotionEvent arg1) {
				// TODO Auto-generated method stub

			}
		});
		//Scanvas width height 넣기//onsizechanged
		
		SCANVAS_HEIGHT = mSCanvas.getHeight();
		SCANVAS_WIDTH = mSCanvas.getWidth();
		Log.d(TAG, "SCANVAS"+SCANVAS_HEIGHT+"width:"+SCANVAS_WIDTH);
		
		// Resource
		HashMap<String, Integer> settingResourceMap = new HashMap<String, Integer>();
		//

		// Locale
		settingResourceMap.put(SCanvasConstants.LOCALE_PEN_SETTING_TITLE,
				R.string.pen_settings);
		settingResourceMap.put(SCanvasConstants.LOCALE_ERASER_SETTING_TITLE,
				R.string.eraser_settings);
		settingResourceMap.put(SCanvasConstants.LOCALE_ERASER_SETTING_CLEARALL,
				R.string.clear_all);
		settingResourceMap.put(
				SCanvasConstants.LOCALE_ERASER_SETTING_CLEARALL_MESSAGE,
				R.string.confirm_clear_all);

		/*
		 * public void createSettingView(ViewGroup settingViewParent,
		 * java.util.HashMap<java.lang.String,java.lang.Integer>
		 * settingResourcesInt,
		 * java.util.HashMap<java.lang.String,java.lang.String>
		 * settingResourcesString, boolean bClearAllVisibileInEraserSetting)
		 * 리소스해시 맵을 바탕으로 S-Canvas에서 세팅 관련된 설정창을 만들어 준다. Parameters:
		 * settingViewParent - 설정창을 추가할 부모 레이아웃. settingResourcesInt - 세팅 관련된
		 * 리소스아이디 참조 해시 맵. settingResourcesString - 세팅 관련된 스트링 참조 해시 맵 (폰트이름 설정
		 * 등에사용). bClearAllVisibileInEraserSetting - 지우개 설정창에 "모두 삭제" 버튼을 보일지
		 * 여부.
		 */
		boolean bClearAllVisibileInEraserSetting = true;
		// FrameLayout settingViewContainer = (FrameLayout)
		// findViewById(R.id.frame_layout);
		settingViewContainer = (RelativeLayout) findViewById(R.id.scanvas_layout);
		mSCanvas.createSettingView(settingViewContainer, settingResourceMap,
				bClearAllVisibileInEraserSetting);

		mSCanvas.setSCanvasInitializeListener(mSCanvasInitializeListener);
		mSCanvas.setHistoryUpdateListener(mHistoryUpdateListener);
		mSCanvas.setSettingStrokeChangeListener(mSettingStrokeChangeListener);

	}
	
	public void onClick(View v) {

	}
	
	
	
	//절대좌표를 상대좌표로 변경하여 전역변수  mX, mY에 대입 
	public void relativeCoordinate(float x , float y){
		
		
	}

	public static class TakeNotePagerAdapter extends FragmentPagerAdapter {

		public TakeNotePagerAdapter(FragmentManager fm) {
			super(fm);
			// TODO Auto-generated constructor stub
		}

		@Override
		public Fragment getItem(int arg0) {
			// TODO Auto-generated method stub
			return TakeNoteFragment.newInstance(arg0);
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return images.length;
		}

	}

	public static class TakeNoteFragment extends Fragment {
		int mNum;
		static View iv;
		// JM)) take note 할 프래그먼트 인플레이터 시킴 >>현재 이미지 뷰만 있음!
		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container,
				Bundle savedInstanceState) {
			// JM 받은 번들 args 의 index 값을 mNum에 넣어줌
			mNum = getArguments() != null ? getArguments().getInt("index") : 1;

			// JM))getView 중요함 fragment에서만 있음
			View v = inflater.inflate(R.layout.take_nate_ppt_viewer, container,
					false);
			// ImageView iv = (ImageView)
			// getView().findViewById(R.id.imageView1);
			iv = v.findViewById(R.id.imageView1);
			((ImageView) iv).setImageResource(images[mNum]);
			
			
			
			
			return v;
		}
		@Override
		public void onResume() {
			// TODO Auto-generated method stub
			
			super.onResume();
			//이미지뷰 width
			IMAGEVIEW_HEIGHT = iv.getHeight();
			IMAGEVIEW_WIDTH = iv.getWidth();
			Log.d(TAG, "ImageView:"+IMAGEVIEW_HEIGHT+","+IMAGEVIEW_WIDTH);
		}

		static TakeNoteFragment newInstance(int index) {

			TakeNoteFragment takeNoteF = new TakeNoteFragment();
			// JM)) Supply index input as an argument.
			Bundle args = new Bundle();
			args.putInt("index", index);
			takeNoteF.setArguments(args);
			
//			IMAGEVIEW_HEIGHT = iv.getHeight();
//			IMAGEVIEW_WIDTH = iv.getWidth();
//			Log.d(TAG, "ImageView:"+IMAGEVIEW_HEIGHT+","+IMAGEVIEW_WIDTH);

			return takeNoteF;
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_main, menu);
		int base = Menu.FIRST;
		// public abstract MenuItem add (int groupId, int itemId, int order,
		// CharSequence title)
		// MenuItem item01 = menu.add(base, base, Menu.NONE, "TakeNote");
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if (item.getItemId() == R.id.takenote) {
			if (mCanvasIndex == 0) {
				settingViewContainer.setVisibility(View.INVISIBLE);
				mLinear.setVisibility(View.INVISIBLE);
				Toast.makeText(getApplicationContext(), "클릭 ㅋㅋㅋ",
						Toast.LENGTH_LONG).show();
				mCanvasIndex = 1;
			} else if (mCanvasIndex == 1) {

				// 현재페이지과 같으면
				if (mOldPager == mPager.getCurrentItem()) {

				} else {
					// 다르면 클리어
					mSCanvas.clearScreen();
					mOldPager = mPager.getCurrentItem();

				}
				mLinear.setVisibility(View.VISIBLE);
				settingViewContainer.setVisibility(View.VISIBLE);
				Toast.makeText(getApplicationContext(), "클릭 ㅋㅋㅋ",
						Toast.LENGTH_LONG).show();
				mCanvasIndex = 0;
			}

		} else if (item.getItemId() == R.id.sms) {
			SMSReceive smsAsync = new SMSReceive();
			smsAsync.execute();
		}
		return false;
	}

	// SMS 관련
	public static final String MESSAGE_TYPE_INBOX = "1";
	public static final String MESSAGE_TYPE_SENT = "2";
	public static final String MESSAGE_TYPE_CONVERSATIONS = "3";
	public static final String MESSAGE_TYPE_NEW = "new";

	public void SMSList() {
		try {
			// Retrieve All SMS
			/*
			 * Inbox = "content://sms/inbox" Failed = "content://sms/failed"
			 * Queued = "content://sms/queued" Sent = "content://sms/sent" Draft
			 * = "content://sms/draft" Outbox = "content://sms/outbox"
			 * Undelivered = "content://sms/undelivered" All =
			 * "content://sms/all" Conversations = "content://sms/conversations"
			 * 
			 * addressCol= mCurSms.getColumnIndex("address"); personCol=
			 * mCurSms.getColumnIndex("person"); dateCol =
			 * mCurSms.getColumnIndex("date"); protocolCol=
			 * mCurSms.getColumnIndex("protocol"); readCol =
			 * mCurSms.getColumnIndex("read"); statusCol =
			 * mCurSms.getColumnIndex("status"); typeCol =
			 * mCurSms.getColumnIndex("type"); subjectCol =
			 * mCurSms.getColumnIndex("subject"); bodyCol =
			 * mCurSms.getColumnIndex("body");
			 */
			Cursor cur;
			int count;
			Uri allMessage = Uri
					.parse("content://com.sec.mms.provider/message");
			cur = MainActivity.this.getContentResolver().query(allMessage,
					null, null, null, null);
			count = cur.getCount();
			Log.i(TAG, "SMS count = " + count);
			String row = "";
			String msg = "";
			String date = "";
			String protocol = "";
			cur.moveToNext();
			do {
				row = cur.getString(cur.getColumnIndex("address"));
				msg = cur.getString(cur.getColumnIndex("body"));
				date = cur.getString(cur.getColumnIndex("date"));
				protocol = cur.getString(cur.getColumnIndex("protocol"));
				Log.d(TAG, "SMS PROTOCOL = " + protocol);

				String type = "";
				if (protocol == MESSAGE_TYPE_SENT)
					type = "sent";
				else if (protocol == MESSAGE_TYPE_INBOX)
					type = "receive";
				else if (protocol == MESSAGE_TYPE_CONVERSATIONS)
					type = "conversations";
				else if (protocol == null)
					type = "send";

				Log.i(TAG, "SMS Phone: " + row + " / Mesg: " + msg
						+ " / Type: " + type + " / Date: " + date);

			} while (cur.moveToNext());
			// parse SMS message

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void SMSDelete() {
		Uri deleteUri = Uri.parse("content://sms");
		int count = 0;
		Cursor c = this.getContentResolver().query(deleteUri, null, null, null,
				null);
		while (c.moveToNext()) {
			try {
				// Delete the SMS
				String pid = c.getString(0);
				// Get id;
				String uri = "content://sms/" + pid;
				// count = this.getContentResolver().delete(Uri.parse(uri),null,
				// null);
			} catch (Exception e) {
			}
		}
	}

	class pptRecieve extends AsyncTask<String, String, String> {

		@Override
		protected String doInBackground(String... params) {
			// TODO Auto-generated method stub
			return null;
		}

	}

	class SMSReceive extends AsyncTask<String, String, String> {

		@Override
		protected void onPreExecute() {
			Toast.makeText(getApplicationContext(), "시작", Toast.LENGTH_SHORT)
					.show();
			super.onPreExecute();
		}

		@Override
		protected String doInBackground(String... params) {
			SMSList();
			return null;
		}

		@Override
		protected void onPostExecute(String result) {
			Toast.makeText(getApplicationContext(), "완료", Toast.LENGTH_SHORT)
					.show();
			super.onPostExecute(result);
		}

	}
}
